package com.example.kmpdemo

import androidx.compose.animation.AnimatedVisibility
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier

/**
 * @author: njb
 * @date:   2025/1/22 0:19
 * @desc:   描述
 */
@Composable
@Preview
fun App() {
    MaterialTheme {
        var showContent by remember { mutableStateOf(false) }
        var showDialog by remember { mutableStateOf(false) }
        Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
            Button(onClick = { showContent = !showContent }) {
                Text("Click me")
            }
            Button(onClick = { showDialog = !showDialog }) {
                Text("show Dialog")
            }
            AnimatedVisibility(showContent) {
                val greeting = remember { Greeting().greet() }
                Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
                    Image(painterResource(Res.drawable.compose_multiplatform), null)
                    Text("Compose: $greeting")
                }
            }
            AnimatedVisibility(showDialog) {
                Column(Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
                    AlertDialogSample()
                }
            }
        }
    }
}

@Composable
@Preview
fun AlertDialogSample(){
    val dialog = remember { mutableStateOf(true) }
    if(dialog.value){
        AlertDialog(
            onDismissRequest = { dialog.value = false},
            title = { Text(text = "开启位置服务")},
            text = { Text(text = "这将意味着,我们会给您提供精准的位置服务，并且您将接受关于您订阅的位置信息。") },
            confirmButton = {
                TextButton(
                    onClick = { dialog.value = false}
                ){
                    Text(text = "同意")
                }
            },
            dismissButton = {
                TextButton(
                    onClick = {
                        dialog.value = false
                    }
                ){
                    Text(text = "取消")
                }
            }

        )
    }
}